<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #box {
            width: 500px;
            height: 500px;
            margin: 20px auto;
        }
        
        .dv1 {
            width: 150px;
            height: 150px;
            background-color: red;
            /* display: none; */
        }
        
        p {
            margin-bottom: 30px
        }
        
        p button {
            width: 25px;
            height: 25px;
        }
    </style>
</head>

<body>
    <div id="box">
        <p>
            <button @click="jian">-</button> {{num}}
            <button @click="add">+</button>
        </p>


        <button @click="sx">显示</button>
        <button @click="xs">消失</button>
        <div class="dv1" v-show="flag">

        </div>
    </div>
</body>
<script src="./vue-2.4.0.js"></script>
<script>
    new Vue({
        el: "#box",

        data: {
            num: 5,
            flag: false,
        },
        methods: {
            jian() {
                this.num--
                    if (this.num % 2 != 0) {
                        this.flag = false
                    } else {
                        this.flag = true
                    }
            },
            add() {
                this.num++
                    if (this.num % 2 == 0) {
                        this.flag = true
                    } else {
                        this.flag = false
                    }
            },
            xs() {
                this.flag = false
            },
            sx() {
                this.flag = true
            },

        },
    })
</script>

</html>